#include "KnowledgeBaseWriterFile.h"
#include "KnowledgeBaseWriterText.h"
#include "KnowledgeBaseInterpreter.h"
#include "Localization.h"
#include "TextStreamStandardIO.h"
#include "WorkModeReceiver.h"
#include <iostream>

Factory < WorkModeReceiverInterface > WorkModeReceiver::factory;

WorkModeReceiver::WorkModeReceiver ()
{
}

WorkModeReceiverInterfacePtr WorkModeReceiver::Spawn ()
{
	return factory.CreateNewObject < WorkModeReceiver > ();
}

void WorkModeReceiver::CheckInnocence ()
{
	assert ( factory.ObjectsCount () == 0 );
}

void WorkModeReceiver::CreateNew ()
{
	std::cout << Localization ()->SelectedCreateNew () << "\n\r";
	
	TextStreamInterfacePtr stream = TextStreamStandardIO::Spawn ();
	KnowledgeBaseMemoryInterfacePtr memory = KnowledgeBaseMemory::Spawn ();
	KnowledgeBaseInterpreterInterfacePtr interpreter = KnowledgeBaseInterpreter::Spawn ( memory );
	KnowledgeBaseWriterInterfacePtr writerText = KnowledgeBaseWriterText::Spawn 
		( stream
		, Localization ()->KnowledgeBaseWriterTextLocalization ()
		);
	KnowledgeBaseWriterInterfacePtr writerFile = KnowledgeBaseWriterFile::Spawn ( stream );
	
	std::cout << Localization ()->EnterCommand () << Localization ()->SampleCommand () << ";\n\r";
	interpreter->Interpret ( Localization ()->SampleCommand () );
	writerText->Write ( memory );
	std::cout << "\n\r" << Localization ()->PhrasesFile () << ":\n\r";
	writerFile->Write ( memory );
	
	writerFile.Delete ();
	writerText.Delete ();
	interpreter.Delete ();
	memory.Delete ();
	stream.Delete ();
}

void WorkModeReceiver::OpenExisting ()
{
	std::cout << Localization ()->SelectedOpenExisting () << "\n\r";
}

void WorkModeReceiver::ChangeDesignation ()
{
	std::cout << Localization ()->SelectedChangeDesignation () << "\n\r";
}

void WorkModeReceiver::MakeCopy ()
{
	std::cout << Localization ()->SelectedMakeCopy () << "\n\r";
}

void WorkModeReceiver::Quit ()
{
	std::cout << Localization ()->SelectedQuit () << "\n\r";
}

void WorkModeReceiver::DeleteToTrashCan ()
{
	std::cout << Localization ()->SelectedDeleteToTrashCan () << "\n\r";
}

void WorkModeReceiver::RestoreFromTrashCan ()
{
	std::cout << Localization ()->SelectedRestoreFromTrashCan () << "\n\r";
}

void WorkModeReceiver::ExtractFromPackage ()
{
	std::cout << Localization ()->SelectedExtractFromPackage () << "\n\r";
}

void WorkModeReceiver::ImportFromFoxPro ()
{
	std::cout << Localization ()->SelectedImportFromFoxPro () << "\n\r";
}

void WorkModeReceiver::ImportFromOracle ()
{
	std::cout << Localization ()->SelectedImportFromOracle () << "\n\r";
}
